package com.jy.wms.common.generator;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @ClassName: MysqlConnection
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author zzp
 * @Date 2017/8/23 22:08
 */
public class MysqlConnection {
    //创建连接
    public  static Connection con = null;
    PreparedStatement pStemt = null;
    public PreparedStatement getMysqlConnection(String sql){
        Properties prop=getProperties("/createBean.properties");
        String url=prop.getProperty("URL");
        String pass=prop.getProperty("PASS");
        String driver=prop.getProperty("DRIVER");
        String name=prop.getProperty("NAME");
        try{
            Class.forName(driver);
            con = DriverManager.getConnection(url,name,pass);
            pStemt = con.prepareStatement(sql);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
        return pStemt;
    }
    public void closeConnection() throws SQLException {
        con.close();
    }
    public Properties getProperties(String filepath){
        Properties prop =  new  Properties();
        InputStream ins =Object.class.getResourceAsStream(filepath);
        try{
            prop.load(ins);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
        return prop;
    }

}
